package demo3;

import java.util.Comparator;
import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-06-28
 * Time: 19:29
 */

public class Student implements Comparable<Student> {
    private String name;
    private int age;

    public Student(){

    }
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }


    @Override
    public int compareTo(Student o) {
        //如果年龄相同按照姓名来排序
        int num = this.age - o.age;
        int num2 = num==0?(this.name.compareTo(o.name)):num;
        return num2;
    }
}
